package top.kwanghuee.shop.product.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.kwanghuee.domain.Product;
import top.kwanghuee.shop.service.ProductService;

import javax.annotation.Resource;

/**
 * @author: kwanghuee
 * @date: 2020/9/11 13:53
 */
@RestController
@Slf4j
public class ProductController {

    @Resource
    private ProductService productService;

    @RequestMapping("/product/api1/demo1")
    public String demo1() {
        return "demo1";
    }

    @RequestMapping("/product/api1/demo2")
    public String demo2() {
        return "demo2";
    }

    @RequestMapping("/product/api2/demo1")
    public String demo3() {
        return "demo3";
    }

    @RequestMapping("/product/api2/demo2")
    public String demo4() {
        return "demo4";
    }

    @GetMapping("/product/{pid}")
    public Product findByPid(@PathVariable("pid") int pid) {
        Product product = productService.findByPid(pid);
        log.info("查询到{}号商品的信息--->{}", pid, JSON.toJSONString(product));
        return product;
    }
}
